package com.turing.post.report.impl;

import java.math.BigInteger;

import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.turing.post.report.util.MerchantPastIncome;
import com.turing.post.report.util.MerchantPastIncomeDao;
import com.turing.post.util.GeneralDao;
import com.turing.post.util.PCPSApplicationException;

@Stateless(mappedName = "report.impl.MerchantPastIncomeDaoImpl")
@Remote
@Local
public class MerchantPastIncomeDaoImpl implements MerchantPastIncomeDao {

	
	
	/**
	 * 实体管理器
	 * 
	 * @see javax.persistence.EntityManager
	 */
	@PersistenceContext
	protected EntityManager _em;
	
	/**
	 * 检测某策略是否追溯过，一条策略只能追溯一次，如追溯过返回true否则返回false
	 */
	@Override
	public boolean check_FeePolicy(BigInteger FeePolicyId){
		// TODO Auto-generated method stub
		String sql="select count(*) from MerchantPastIncome t where t.feepolicyid=?1";
		Query query = _em.createNativeQuery(sql);
		query.setParameter(1, FeePolicyId);
		int i=Integer.parseInt(query.getSingleResult().toString());
		if(i>0)
			return true;
		return false;
	}

	@Override
	public void insertMerchantPastIncome(
			MerchantPastIncome merchantPastIncome) throws PCPSApplicationException{
		
		GeneralDao.insert(_em, merchantPastIncome);
		
	}

}
